package com.ohuang.myapp.presenter;

import com.ohuang.baseapp.mvp.BaseObserver;
import com.ohuang.baseapp.mvp.BaseRxPresenter;
import com.ohuang.myapp.bean.WYNewsBean;
import com.ohuang.myapp.model.ListFgModel;
import com.ohuang.myapp.view.IListFgView;
import io.reactivex.rxjava3.annotations.NonNull;
import io.reactivex.rxjava3.disposables.CompositeDisposable;
import org.jetbrains.annotations.NotNull;

public class ListFgPresenter extends BaseRxPresenter<IListFgView> {
    ListFgModel listFgModel = new ListFgModel();
    CompositeDisposable compositeDisposable = new CompositeDisposable();

    @Override
    public void attachView(IListFgView view) {
        super.attachView(view);

    }

    public void LoadData(int page) {
        addDisposable(listFgModel.loadData(page + "", "10"), new BaseObserver<WYNewsBean>() {
            @Override
            public void onNext(@NotNull WYNewsBean wyNewsBean) {
                if (wyNewsBean.getCode() == 200) {
                    mView.LoadData(wyNewsBean);
                    mView.refreshOk();
                } else {
                    mView.ShowToast(wyNewsBean.getMessage());
                }
            }

            @Override
            public void onError(@NonNull Throwable e) {
                super.onError(e);
                mView.ShowToast(e.getMessage());
            }
        });
    }


    public void LoadMore(int page) {
        addDisposable(listFgModel.loadData(page + "", "10"), new BaseObserver<WYNewsBean>() {
            @Override
            public void onNext(@NonNull WYNewsBean wyNewsBean) {
                if (wyNewsBean.getCode() == 200) {
                    mView.LoadMoreData(wyNewsBean);
                    mView.refreshOk();
                } else {
                    mView.ShowToast(wyNewsBean.getMessage());
                }
            }

            @Override
            public void onError(@NonNull Throwable e) {
                mView.ShowToast(e.getMessage());
            }

        });

    }

}
